namespace GemBox.Spreadsheet
{
    using System;
    using System.Globalization;

    internal class NumbersParser
    {
        private static NumberFormatInfo formatProvider = new NumberFormatInfo();

        static NumbersParser()
        {
            formatProvider.NumberDecimalSeparator = ".";
        }

        public static bool IsUshort(double doubleValue)
        {
            return ((doubleValue < 65535.0) && (Math.Ceiling(doubleValue) == doubleValue));
        }

        public static double StrToDouble(string data)
        {
            double num;
            double.TryParse(data, NumberStyles.Float, (IFormatProvider) formatProvider, out num);
            return num;
        }

        public static float StrToFloat(string str)
        {
            double result = 0.0;
            double.TryParse(str, NumberStyles.Float, (IFormatProvider) formatProvider, out result);
            return (float) result;
        }

        public static int StrToInt(string data)
        {
            double result = 0.0;
            double.TryParse(data, NumberStyles.Integer, (IFormatProvider) formatProvider, out result);
            return (int) result;
        }

        public static NumberFormatInfo Provider
        {
            get
            {
                return formatProvider;
            }
        }
    }
}
